let gulp = require("gulp");
let uglify = require("gulp-uglify");
let babel = require("gulp-babel");
let sass = require("gulp-sass");
let webserver = require("gulp-webserver");

gulp.task("start", ["build"], ()=>{
	gulp.src("./dist")
		.pipe(
			webserver({
				livereload : true,
				proxies : [
					{
						source : "/list",
						target : "http://xxxxxxxxxx"
					}
				]
			})
		)
	gulp.watch("./src/**/*.scss", ["compileCSS"]);
	gulp.watch("./src/**/*.js", ["compileJS"]);
	gulp.watch("./src/**/*.html", ["compileHTML"]);
	gulp.watch("./src/static/**/*", ["static"]);
	gulp.watch("./src/conf/**/*", ["conf"]);
})

gulp.task("build", ["compileCSS","compileJS", "compileHTML", "static", "conf"])

gulp.task("compileJS", ()=> {
	gulp.src("./src/scripts/**/*.js")
		.pipe(
			babel({
				presets: ['@babel/env']
			})
		)
		//.pipe( uglify() )
		.pipe( gulp.dest("./dist/scripts/") )
	gulp.src("./src/pages/**/*.js")
		.pipe(
			babel({
				presets: ['@babel/env']
			})
		)
		//.pipe( uglify() )
		.pipe( gulp.dest("./dist/pages/") )
})

gulp.task("compileCSS", ()=> {
	gulp.src("./src/styles/**/*.scss")
		.pipe( sass() )
		.pipe( gulp.dest("./dist/styles/") )
})

gulp.task("compileHTML", ()=>{
	gulp.src("./src/pages/**/*.html")
		.pipe( gulp.dest("./dist/pages") )
})

gulp.task("static", ()=>{
	gulp.src("./src/static/**/*.*")
		.pipe( gulp.dest("./dist/static") )
})
gulp.task("conf", ()=>{
	gulp.src("./src/conf/**/*.*")
		.pipe( gulp.dest("./dist/conf") )
})